package com.itheima.contoller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @param
 * @return
 */
@WebServlet("/userServlet")
public class UserNameServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置字符集防止乱码
       // req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        //获取Ajax发送的数据
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if ("秃三炮".equals(username)) {
            resp.getWriter().write("<font color='red'>用户名已注册</font>");
        }else if("黄金标".equals(username)){
            resp.getWriter().write(username);
            resp.getWriter().write(password);
        } else {
            resp.getWriter().write("<font color='black'>用户名可用</font>");
        }
        }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
